package Common

import (
	"crypto/md5"
	"crypto/rand"
	"encoding/base64"
	"encoding/hex"
	"io"
)


//生成32位md5字串
func GetMd5String(s string) string {
	h := md5.New()
	h.Write([]byte(s))
	a:= hex.EncodeToString(h.Sum(nil))
	str:=[]byte(a)
	str2:=make([]byte,0)
	i:=0
	for _,v:=range str{
		if i==8||i==12||i==16||i==20{
			str2=append(str2, '-')
		}
		str2=append(str2, v)
		i++
	}
	return string(str2)
}

//生成Guid字串
func GetGuid() string {
	b := make([]byte, 48)

	if _, err := io.ReadFull(rand.Reader, b); err != nil {
		return ""
	}
	return GetMd5String(base64.URLEncoding.EncodeToString(b))
}